#ifndef DW_BASE_POINTER_INL
#	define DW_BASE_POINTER_INL

namespace dw {
	namespace base {

template< typename T >
inline Pointer< T >::Pointer(T* ptr /*= NULL*/)
:	m_counter(NULL)
{
	if (ptr != NULL)
		m_counter = new Counter(ptr);
}

template< typename T >
inline Pointer< T >::Pointer(const Pointer< T >& ptr)
{
	acquire(ptr.m_counter);
}

template< typename T >
inline Pointer< T >& Pointer< T >::operator = (const Pointer< T >& rhs)
{
	if (this != &rhs) 
	{
		Release();
		acquire(rhs.m_counter);
	}

	return *this;
}

template< typename T >
inline void Pointer< T >::acquire(Counter* counter)
{
	m_counter = counter;
	if (counter != NULL)
		++(counter->count);
}

template< typename T >
inline void Pointer< T >::release()
{
	if (m_counter != NULL) 
	{
		if (--m_counter->count == 0) 
		{
			delete m_counter->ptr;
			delete m_counter;
		}
		m_counter = NULL;
	}
}

	} // namespace base
} // namespace dw

#endif // !DW_BASE_POINTER_INL
